home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / kdockwidget.h < prev    next >
Encoding:
C/C++ Source or Header  |  2007-10-08  |  45.2 KB  |  1,540 lines

  1. /* This file is part of the KDE libraries
  2.    Copyright (C) 2000 Max Judin <novaprint@mtu-net.ru>
  3.    Copyright (C) 2000 Falk Brettschneider <falk@kdevelop.org>
  4.    Copyright (C) 2002,2003 Joseph Wenninger <jowenn@kde.org>
  5.  
  6.    This library is free software; you can redistribute it and/or
  7.    modify it under the terms of the GNU Library General Public
  8.    License version 2 as published by the Free Software Foundation.
  9.  
  10.    This library is distributed in the hope that it will be useful,
  11.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13.    Library General Public License for more details.
  14.  
  15.    You should have received a copy of the GNU Library General Public License
  16.    along with this library; see the file COPYING.LIB.  If not, write to
  17.    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  18.    Boston, MA 02110-1301, USA.
  19. */
  20.  
  21. /*
  22.    activities:
  23.    -----------
  24.    05/2001 -               : useful patches, bugfixes by Christoph Cullmann <crossfire@babylon2k.de>,
  25.                              Joseph Wenninger <jowenn@bigfoot.com> and  Falk Brettschneider
  26.    03/2001 - 05/2001       : maintained and enhanced by Falk Brettschneider <falk@kdevelop.org>
  27.    03/2000                 : class documentation added by Falk Brettschneider <gigafalk@yahoo.com>
  28.    10/1999 - 03/2000       : programmed by Max Judin <novaprint@mtu-net.ru>
  29.  
  30.    C++ classes in this file:
  31.    -------------------------
  32.    - KDockWidgetAbstractHeader     - minor helper class
  33.    - KDockWidgetAbstractHeaderDrag - minor helper class
  34.    - KDockWidgetHeaderDrag         - drag panel in a dockwidget title bar
  35.    - KDockWidgetHeader             - dockwidget title bar containing the drag panel
  36.    - KDockTabGroup                 - minor helper class
  37.    - KDockWidget                   - IMPORTANT CLASS: the one and only dockwidget class
  38.    - KDockManager                  - helper class
  39.    - KDockMainWindow               - IMPORTANT CLASS: a special KMainWindow that can have dockwidgets
  40.    - KDockArea                     - like KDockMainWindow but inherits just QWidget
  41.  
  42.    IMPORTANT Note: This file compiles also in Qt-only mode by using the NO_KDE2 precompiler definition!
  43. */
  44.  
  45.  
  46. #ifndef KDOCKWIDGET_H
  47. #define KDOCKWIDGET_H
  48.  
  49. #define _KDOCKWIDGET_2_2_
  50.  
  51. #include <qpoint.h>
  52. #include <qptrlist.h>
  53. #include <qframe.h>
  54. #include <qdom.h>
  55. #include <qtabwidget.h>
  56.  
  57. #ifndef NO_KDE2
  58. #include <kmainwindow.h>
  59. #include <netwm_def.h>
  60. #else
  61.  
  62. #include <qmainwindow.h>
  63. #include "exportdockclass.h"
  64. #include "dummykmainwindow.h"
  65. #endif
  66.  
  67. class KDockSplitter;
  68. class KDockManager;
  69. class KDockMoveManager;
  70. class KDockWidget;
  71. class KDockButton_Private;
  72. class KDockWidgetPrivate;
  73. class KDockWidgetHeaderPrivate;
  74. class KDockArea;
  75.  
  76. class QObjectList;
  77. class QPopupMenu;
  78. class QVBoxLayout;
  79. class QHBoxLayout;
  80. class QPixmap;
  81.  
  82. #ifndef NO_KDE2
  83. class KToolBar;
  84. class KConfig;
  85. #else
  86. class QToolBar;
  87. #endif
  88.  
  89. class KDockContainer;
  90.  
  91. namespace KMDI
  92. {
  93.   class MainWindow;
  94. }
  95.  
  96. /**
  97.  * An abstract base clase for all dockwidget headers (and member of the dockwidget class set).
  98.  * See the class description of KDockWidgetHeader!
  99.  * More or less a minor helper class for the dockwidget class set.
  100.  *
  101.  * @author Max Judin (documentation: Falk Brettschneider).
  102.  */
  103. class KDEUI_EXPORT KDockWidgetAbstractHeader : public QFrame
  104. {
  105.   Q_OBJECT
  106. public:
  107.  
  108.   /**
  109.    * Constructs this.
  110.    *
  111.    * @param parent the parent widget (usually a dockwidget)
  112.    * @param name   the object instance name
  113.    */
  114.   KDockWidgetAbstractHeader( KDockWidget* parent, const char* name = 0L );
  115.  
  116.   /**
  117.    * Destructs this.
  118.    */
  119.   virtual ~KDockWidgetAbstractHeader(){}
  120.  
  121.   /**
  122.    * Provides things concerning to switching to toplevel mode. Must be overridden by an inheriting class.
  123.    */
  124.   virtual void setTopLevel( bool ){}
  125.  
  126. #ifndef NO_KDE2
  127.   /**
  128.    * Provides saving the current configuration. Must be overridden by an inheriting class.
  129.    */
  130.   virtual void saveConfig( KConfig* ){}
  131.  
  132.   /**
  133.    * Provides loading the current configuration.  Must be overridden by an inheriting class
  134.    */
  135.   virtual void loadConfig( KConfig* ){}
  136. #endif
  137.  
  138. protected:
  139.   virtual void virtual_hook( int id, void* data );
  140. private:
  141.   class KDockWidgetAbstractHeaderPrivate;
  142.   KDockWidgetAbstractHeaderPrivate *d;
  143. };
  144.  
  145. /**
  146.  * An abstract class for all dockwidget drag-panels of a dockwidgets (and member of the dockwidget class set).
  147.  * See the class description of KDockWidgetHeaderDrag!
  148.  * More or less a minor helper class for the dockwidget class set.
  149.  *
  150.  * @author Max Judin (documentation: Falk Brettschneider).
  151.  */
  152. class KDEUI_EXPORT KDockWidgetAbstractHeaderDrag : public QFrame
  153. {
  154.   Q_OBJECT
  155. public:
  156.  
  157.   /**
  158.    * Constructs this.
  159.    *
  160.    * @param parent the parent widget (usually a dockwidget header)
  161.    * @param dock   the dockwidget where it belongs to
  162.    * @param name   the object instance name
  163.    */
  164.   KDockWidgetAbstractHeaderDrag( KDockWidgetAbstractHeader* parent,
  165.                                  KDockWidget* dock, const char* name = 0L );
  166.  
  167.   /**
  168.    * Destructs this.
  169.    */
  170.   virtual ~KDockWidgetAbstractHeaderDrag(){}
  171.  
  172.   /**
  173.    * @return the dockwidget where this belongs to
  174.    */
  175.   KDockWidget* dockWidget() const { return dw; }
  176.  
  177. private:
  178.   /**
  179.    * the dockwidget where this belongs to
  180.    */
  181.   KDockWidget* dw;
  182. protected:
  183.   virtual void virtual_hook( int id, void* data );
  184. private:
  185.   class KDockWidgetAbstractHeaderDragPrivate;
  186.   KDockWidgetAbstractHeaderDragPrivate *d;
  187. };
  188.  
  189. /**
  190.  * This special widget is the panel one can grip with the mouses (and member of the dockwidget class set).
  191.  * The widget for dragging, so to speak.
  192.  * Usually it is located in the KDockWidgetHeader.
  193.  * More or less a minor helper class for the dockwidget class set.
  194.  *
  195.  * @author Max Judin (documentation: Falk Brettschneider).
  196.  */
  197. class KDEUI_EXPORT KDockWidgetHeaderDrag : public KDockWidgetAbstractHeaderDrag
  198. {
  199.   Q_OBJECT
  200. public:
  201.  
  202.   /**
  203.    * Constructs this.
  204.    *
  205.    * @param parent the parent widget (usually a dockwidget header)
  206.    * @param dock   the dockwidget where it belongs to
  207.    * @param name   the object instance name
  208.    */
  209.   KDockWidgetHeaderDrag( KDockWidgetAbstractHeader* parent, KDockWidget* dock,
  210.                          const char* name = 0L );
  211.  
  212.   /**
  213.    * Destructs this.
  214.    */
  215.   virtual ~KDockWidgetHeaderDrag(){}
  216.  
  217. protected:
  218.  
  219.   /**
  220.    * Draws the drag panel (a double line)
  221.    */
  222.   virtual void paintEvent( QPaintEvent* );
  223.  
  224. protected:
  225.   virtual void virtual_hook( int id, void* data );
  226. private:
  227.   class KDockWidgetHeaderDragPrivate;
  228.   KDockWidgetHeaderDragPrivate *d;
  229. };
  230.  
  231. /**
  232.  * The header (additional bar) for a KDockWidget s (and member of the dockwidget class set).
  233.  * It have got the buttons located there. And it is for recording and reading the button states.
  234.  * More or less a minor helper class for the dockwidget class set.
  235.  *
  236.  * @author Max Judin (documentation: Falk Brettschneider).
  237.  */
  238. class KDEUI_EXPORT KDockWidgetHeader : public KDockWidgetAbstractHeader
  239. {
  240.   Q_OBJECT
  241. public:
  242.  
  243.   /**
  244.    * Constructs this.
  245.    *
  246.    * @param parent the parent widget (usually a dockwidget)
  247.    * @param name   the object instance name
  248.    */
  249.   KDockWidgetHeader( KDockWidget* parent, const char* name = 0L );
  250.  
  251.   /**
  252.    * Destructs this.
  253.    */
  254.   virtual ~KDockWidgetHeader(){}
  255.  
  256.   /**
  257.    * Hides the close button and stay button when switching to toplevel or vice versa shows them.
  258.    *
  259.    * @param t toplevel or not
  260.    */
  261.   virtual void setTopLevel( bool t);
  262.  
  263.   /**
  264.    * Sets the drag panel of this header.
  265.    *
  266.    * @param nd A pointer to the new drag panel
  267.    */
  268.   void setDragPanel( KDockWidgetHeaderDrag* nd );
  269.  
  270.   /**
  271.    * Get the drag panel of this header.
  272.    *
  273.    * @since 3.4
  274.    */
  275.    KDockWidgetHeaderDrag *dragPanel();
  276.  
  277.   bool dragEnabled() const;
  278.   void setDragEnabled(bool b);
  279.   /// @since 3.1
  280.   void showUndockButton(bool show);
  281.  
  282.   /// @since 3.2
  283.   void forceCloseButtonHidden(bool enable=true);
  284. #ifndef NO_KDE2
  285.   /**
  286.    * Saves the current button state to a KDE config container object.
  287.    *
  288.    * @param c the configuration safe
  289.    */
  290.   virtual void saveConfig( KConfig* c);
  291.  
  292.   /**
  293.    * Loads the current button state from a KDE config container object.
  294.    *
  295.    * @param c the configuration safe
  296.    */
  297.   virtual void loadConfig( KConfig* c);
  298. #endif
  299.  
  300.    /*@since 3.2
  301.     * add an arbitrary button to the dockwidget header
  302.     * NOT PART OF THE PUBLIC API (you don't have access the class defintion anyways, without special
  303.     * header file copying. (don't do it))
  304.     */
  305.     void addButton(KDockButton_Private*);
  306.  
  307.    /*@since 3.2
  308.     * remove an arbtrary button from the dockwidget header
  309.     * NOT PART OF THE PUBLIC API (you don't have access the class defintion anyways, without special
  310.     * header file copying. (don't do it))
  311.     */
  312.     void removeButton(KDockButton_Private*);
  313.  
  314.  
  315.  
  316. protected slots:
  317.   /**
  318.    * Sets dragging the dockwidget off when the stay button is pressed down and vice versa.
  319.    */
  320.   void slotStayClicked();
  321.  
  322. protected:
  323.  
  324.   /**
  325.    * A layout manager for placing the embedded buttons (close and stay)
  326.    */
  327.   QHBoxLayout* layout;
  328.  
  329.   /**
  330.    * a little button for closing (undocking and hiding) the dockwidget
  331.    */
  332.   KDockButton_Private* closeButton;
  333.  
  334.   /**
  335.    * a little button for enabling/disabling dragging the dockwidget with the mouse
  336.    */
  337.   KDockButton_Private* stayButton;
  338.  
  339.   /**
  340.    * a little button for dock back the dockwidget to it's previous dockwidget
  341.    */
  342.   KDockButton_Private* dockbackButton;
  343.  
  344.   /**
  345.    * the drag panel (double line)
  346.    */
  347.   KDockWidgetHeaderDrag* drag;
  348.  
  349. protected:
  350.   virtual void virtual_hook( int id, void* data );
  351. private:
  352.   KDockWidgetHeaderPrivate *d;
  353. };
  354.  
  355. /**
  356.  * It just hides the special implementation of a dockwidget tab groups (and is member of the dockwidget class set).
  357.  * An abstraction what it is currently.
  358.  * In general it is like QTabWidget but is more useful for the dockwidget class set.
  359.  * More or less a minor helper class for the dockwidget class set.
  360.  *
  361.  * @author Max Judin (documentation: Falk Brettschneider).
  362.  */
  363. class KDEUI_EXPORT KDockTabGroup : public QTabWidget
  364. {
  365.   Q_OBJECT
  366. public:
  367.   /**
  368.    * Constructs this. It just calls the method of the base class.
  369.    */
  370.   KDockTabGroup( QWidget *parent = 0, const char *name = 0 )
  371.   :QTabWidget( parent, name ){}
  372.  
  373.   /**
  374.    * Destructs a KDockTabGroup.
  375.    */
  376.   virtual ~KDockTabGroup(){}
  377.  
  378.   QWidget *transientTo();
  379. protected:
  380.   virtual void virtual_hook( int id, void* data );
  381. private:
  382.   class KDockTabGroupPrivate;
  383.   KDockTabGroupPrivate *d;
  384. };
  385.  
  386.  
  387. /**
  388.  * Floatable widget that can be dragged around with the mouse and
  389.  * encapsulate the actual widgets (and member of the dockwidget class
  390.  * set).
  391.  *
  392.  * You just grip the double-lined panel, tear it off its parent
  393.  * widget, drag it somewhere and let it loose. Depending on the
  394.  * position where you leave it, the dockwidget becomes a toplevel
  395.  * window on the desktop (floating mode) or docks to a new widget
  396.  * (dock mode). Note: A KDockWidget can only be docked to a
  397.  * KDockWidget.
  398.  *
  399.  * If you want to use this kind of widget, your main application
  400.  * window has to be a KDockMainWindow.  That is because it has
  401.  * got several additional dock management features, for instance a
  402.  * KDockManager that has an overview over all dockwidgets and and
  403.  * a dockmovemanager (internal class) that handles the dock process.
  404.  *
  405.  * Usually you create an KDockWidget that covers the actual widget in this way:
  406.  * \code
  407.  * ...
  408.  * KDockMainWindow* mainWidget;
  409.  * ...
  410.  * KDockWidget* dock = 0L;
  411.  * dock = mainWidget->createDockWidget( "Any window caption", nicePixmap, 0L, i18n("window caption")); // 0L==no parent
  412.  * QWidget* actualWidget = new QWidget( dock);
  413.  * dock->setWidget( actualWidget); // embed it
  414.  * dock->setToolTipString(i18n("That's me")); // available when appearing as tab page
  415.  * ...
  416.  * \endcode
  417.  *
  418.  * See KDockMainWindow how a dockwidget is docked in.
  419.  *
  420.  *
  421.  * @author Max Judin (documentation: Falk Brettschneider).
  422.  */
  423. class KDEUI_EXPORT KDockWidget: public QWidget
  424. {
  425.   Q_OBJECT
  426. friend class KDockManager;
  427. friend class KDockSplitter;
  428. friend class KDockMainWindow;
  429. friend class KDockArea;
  430.  
  431. public:
  432.   /**
  433.    * Construct a dockwidget.
  434.    *
  435.    * Initially, docking to another and docking to this is allowed for
  436.    * every @p DockPosition.  It is supposed to be no (tab) group. It will
  437.    * taken under control of its dockmanager.
  438.    *
  439.    * @param dockManager The responsible manager (dock helper)
  440.    * @param name        Object instance name
  441.    * @param pixmap      An icon (for instance shown when docked centered)
  442.    * @param parent      Parent widget
  443.    * @param strCaption  Title of the dockwidget window (shown when toplevel)
  444.    * @param strTabPageLabel The title of the tab page (shown when in tab page mode), if it is "", only the icon will be shown, if it is 0L, the label is set to strCaption
  445.    * @param f Qt::WidgetFlags widget flags
  446.    */
  447.   KDockWidget( KDockManager* dockManager, const char* name,
  448.                const QPixmap &pixmap, QWidget* parent = 0L, const QString& strCaption = QString::null,
  449.                const QString& strTabPageLabel = QString::fromLatin1( " " ), WFlags f = 0);
  450.  
  451.   /**
  452.    * Destructs a dockwidget.
  453.    */
  454.   virtual ~KDockWidget();
  455.  
  456.   /**
  457.    * The possible positions where a dockwidget can dock to another dockwidget
  458.    */
  459.   enum DockPosition
  460.   {
  461.     DockNone   = 0,
  462.     DockTop    = 0x0001,
  463.     DockLeft   = 0x0002,
  464.     DockRight  = 0x0004,
  465.     DockBottom = 0x0008,
  466.     DockCenter = 0x0010,
  467.     DockDesktop= 0x0020,
  468.     DockToSpecialSites=0x0040, ///< @since 3.1
  469.     DockCorner = DockTop | DockLeft | DockRight | DockBottom,
  470.     DockFullSite = DockCorner | DockCenter,
  471.     DockFullDocking = DockFullSite | DockDesktop
  472.   };
  473.  
  474.   /**
  475.    * This is a key method of this class! Use it to dock dockwidgets to
  476.    * another dockwidget at the right position within its
  477.    * KDockMainWindow or a toplevel dockwidget.
  478.    *
  479.    *
  480.    * If the target is null, it will become a toplevel dockwidget at position pos;
  481.    * Note: Docking to another dockwidget means exactly:
  482.    * A new parent dockwidget will be created, that replaces the target dockwidget and contains another single helper widget (tab widget or panner)
  483.    * which contains both dockwidgets, this and the target dockwidget. So consider parent<->child relationships change completely during such actions.
  484.    *
  485.    * @param  target The dockwidget to dock to
  486.    * @param  dockPos One of the DockPositions this is going to dock to
  487.    * @param  spliPos The split relation (in percent, or percent*100 in high resolution) between both dockwidgets, target and this
  488.    * @param  pos The dock position, mainly of interest for docking to the desktop (as toplevel dockwidget)
  489.    * @param  check Only for internal use;
  490.    * @param  tabIndex The position index of the tab widget (when in tab page mode), -1 (default) means append
  491.    * @return result The group dockwidget that replaces the target dockwidget and will be grandparent of target and @p this.
  492.    *
  493.    * @note Since KDE 3.5 the splitter position @p spliPos is always a value between [0..100]. If
  494.    *       the value is > 100, it will be treated like the old code and normalized to a value between
  495.    *       0 and 100. Example: If the value was 4000, it will be fixed to 40. In short: The old and
  496.    *       the new behavior both work, so it is compatible with older KDE-versions.
  497.    */
  498.   KDockWidget* manualDock( KDockWidget* target, DockPosition dockPos, int spliPos = 50, QPoint pos = QPoint(0,0), bool check = false, int tabIndex = -1);
  499.  
  500.   /**
  501.    * Specify where it is either possible or impossible for this to dock to another dockwidget.
  502.    *
  503.    * @param pos An OR'ed set of @p DockPositions
  504.    */
  505.   void setEnableDocking( int pos );
  506.  
  507.   /**
  508.    * @return Where it is either possible or impossible for this to dock to another dockwidget (an OR'ed set of DockPositions).
  509.    */
  510.   int enableDocking() const { return eDocking; }
  511.  
  512.   /**
  513.    * Specify where it is either possible or impossible for another dockwidget to dock to this.
  514.    *
  515.    * @param pos An OR'ed set of @p DockPositions
  516.    */
  517.   void setDockSite( int pos ){ sDocking = pos;}
  518.  
  519.   /**
  520.    * @return There it is either possible or impossible for another dockwidget to dock to this (an OR'ed set of @p DockPositions).
  521.    */
  522.   int dockSite() const { return sDocking; }
  523.  
  524.   /**
  525.    * Sets the embedded widget.
  526.    *
  527.    * A QLayout takes care about proper resizing, automatically.
  528.    *
  529.    * @param w The pointer to the dockwidget's child widget.
  530.    */
  531.   void setWidget( QWidget* w);
  532.  
  533.   /**
  534.    * Get the embedded widget.
  535.    *
  536.    * @return The pointer to the dockwidget's child widget, 0L if there's no such child.
  537.    */
  538.   QWidget* getWidget() const { return widget; }
  539.  
  540.   /**
  541.    * Sets the header of this dockwidget.
  542.    *
  543.    * A QLayout takes care about proper resizing, automatically.
  544.    * The header contains the drag panel, the close button and the stay button.
  545.    *
  546.    * @param ah A base class pointer to the dockwidget header
  547.    */
  548.   void setHeader( KDockWidgetAbstractHeader* ah);
  549.  
  550.   /**@since 3.2
  551.    * get the pointer to the header widget
  552.    */
  553.   KDockWidgetAbstractHeader *getHeader();
  554.  
  555.   /**
  556.    * Normally it simply shows the dockwidget.
  557.    *
  558.    * But additionally, if it is docked to a tab widget (@p DockCenter), it is set as the active (visible) tab page.
  559.    */
  560.   void makeDockVisible();
  561.  
  562.   /**
  563.    * @return If it may be possible to hide this.
  564.    *
  565.    * There are reasons that it's impossible:
  566.    * @li It is a (tab) group.
  567.    * @li It is already invisible ;-)
  568.    * @li The parent of this is the KDockMainWindow.
  569.    * @li It isn't able to dock to another widget.
  570.    */
  571.   bool mayBeHide() const;
  572.  
  573.   /**
  574.    * @return If it may be possible to show this.
  575.    * There are reasons that it's impossible:
  576.    * @li It is a (tab) group.
  577.    * @li It is already visible ;-)
  578.    * @li The parent of this is the @p KDockMainWindow.
  579.    */
  580.   bool mayBeShow() const;
  581.  
  582.   /**
  583.    * @return The dockmanager that is responsible for this.
  584.    */
  585.   KDockManager* dockManager() const { return manager; }
  586.  
  587.   /**
  588.    * Stores a string for a tooltip.
  589.    *
  590.    * That tooltip string has only a meaning when this dockwidget is shown as tab page.
  591.    * In this case the tooltip is shown when one holds the mouse cursor on the tab page header.
  592.    * Such tooltip will for instance be useful, if you use only icons there.
  593.    * Note: Setting an empty string switches the tooltip off.
  594.    *
  595.    * @param ttStr A string for the tooltip on the tab.
  596.    */
  597.   void setToolTipString(const QString& ttStr) { toolTipStr = ttStr; }
  598.  
  599.   /**
  600.    * @return The tooltip string being shown on the appropriate tab page header when in dock-centered mode.
  601.    */
  602.   const QString& toolTipString() const { return toolTipStr; }
  603.  
  604.   /**
  605.    * @return result @p true, if a dockback is possible, otherwise @p false.
  606.    */
  607.   bool isDockBackPossible() const;
  608.  
  609.   /**
  610.    * Sets a string that is used for the label of the tab page when in tab page mode
  611.    * @param label The new tab page label.
  612.    */
  613.   void setTabPageLabel( const QString& label) { tabPageTitle = label; }
  614.  
  615.   /**
  616.    * @return A string that is used for the label of the tab page when in tab page mode.
  617.    */
  618.   const QString& tabPageLabel() const { return tabPageTitle; }
  619.  
  620.   /**
  621.    * Catches and processes some QWidget events that are interesting for dockwidgets.
  622.    */
  623.   virtual bool event( QEvent * );
  624.  
  625.   /**
  626.    * Add dockwidget management actions to QWidget::show.
  627.    */
  628.   virtual void show();
  629.   /**
  630.    * @return the parent widget of this if it inherits class KDockTabGroup
  631.    */
  632.   KDockTabGroup* parentDockTabGroup() const;
  633.  
  634.   /// @since 3.1
  635.   QWidget *parentDockContainer() const;
  636.  
  637. #ifndef NO_KDE2
  638.  
  639.   /**
  640.    * Sets the type of the dock window
  641.    *
  642.    * @param windowType is type of dock window
  643.    */
  644.   void setDockWindowType (NET::WindowType windowType);
  645.  
  646. #endif
  647.  
  648.   void setDockWindowTransient (QWidget *parent, bool transientEnabled);
  649.  
  650.   /**
  651.    * Returns the widget this dockwidget is set transient to, otherwise 0
  652.    * @since 3.2
  653.    */
  654.    QWidget *transientTo();
  655.  
  656.   /**
  657.    * Lookup the nearest dockwidget docked left/right/top/bottom to this one or return 0
  658.    *
  659.    * @param pos is the position the wanted widget is docked to this one
  660.    * @since 3.1
  661.    */
  662.   KDockWidget *findNearestDockWidget(DockPosition pos);
  663.  
  664.   /**
  665.    * Allows changing the pixmap which is used for the caption or dock tabs
  666.    *
  667.    * @param pixmap is the pixmap to set
  668.    * @since 3.2
  669.    */
  670.    void setPixmap(const QPixmap& pixmap=QPixmap());
  671.  
  672.   /**
  673.    * Returns the dockwidget's associated caption/dock tab pixmap
  674.    *
  675.    * @since 3.2
  676.    */
  677.    const QPixmap& pixmap() const;
  678.  
  679.   /**
  680.    * @return the current dock position.
  681.    * @since 3.3
  682.    */
  683.   KDockWidget::DockPosition currentDockPosition() const;
  684.  
  685. public slots:
  686.   /**
  687.    * subject to changes. It doesn't completely work yet without small hacks from within the calling application (Perhaps
  688.    * KDE 3.1.x oder 3.2
  689.    * width is in pixel. It only affects a widget, which is placed directly into a horizontal KDockSplitter
  690.    * @since 3.1
  691.    **/
  692.   void setForcedFixedWidth(int);
  693.   /**
  694.    * subject to changes. It doesn't completely work yet without small hacks from within the calling application (Perhaps
  695.    * KDE 3.1.x oder 3.2
  696.    * height is in pixel. It only affects a widget, which is placed directly into a vertical KDockSplitter
  697.    * @since 3.1
  698.    **/
  699.   void setForcedFixedHeight(int);
  700.   /// @since 3.1
  701.   void restoreFromForcedFixedSize();
  702.  
  703.   /// @since 3.1
  704.   int forcedFixedWidth();
  705.   /// @since 3.1
  706.   int forcedFixedHeight();
  707.  
  708.   /**
  709.    * Docks a dockwidget back to the dockwidget that was the neighbor
  710.    widget before the current dock position.
  711.   */
  712.   void dockBack();
  713.  
  714.   /**
  715.    * Toggles the visibility state of the dockwidget if it is able to be shown or to be hidden.
  716.    */
  717.   void changeHideShowState();
  718.  
  719.   /**
  720.    * Undocks this. It means it becomes a toplevel widget framed by the system window manager.
  721.    * A small panel at the top of this undocked widget gives the possibility to drag it into
  722.    * another dockwidget by mouse (docking).
  723.    */
  724.   void undock();
  725.  
  726.   /**
  727.    * Docks the widget to the desktop (as a toplevel widget)
  728.    * @since 3.1
  729.    */
  730.   void toDesktop( );
  731.  
  732. protected:
  733.   friend class KMdiMainFrm;
  734.   friend class KMDI::MainWindow;
  735.   /**
  736.    * Checks some conditions and shows or hides the dockwidget header (drag panel).
  737.    * The header is hidden if:
  738.    * @li the parent widget is the KDockMainWindow
  739.    * @li this is a (tab) group dockwidget
  740.    * @li it is not able to dock to another dockwidget
  741.    */
  742.   void updateHeader();
  743.  
  744.   /// @since 3.1
  745.   void setLatestKDockContainer(QWidget *);
  746.   /// @since 3.1
  747.   QWidget *latestKDockContainer();
  748.  
  749.   /// @since 3.2
  750.   void setFormerBrotherDockWidget(KDockWidget *);
  751.  
  752. signals:
  753.   /**
  754.    *@since 3.2
  755.    *is emitted after the setWidget method has finished
  756.    */
  757.    void widgetSet(QWidget*);
  758.  
  759.   /**
  760.    * Emitted when another dock widget is docking to this.
  761.    *
  762.    * @param dw the dockwidget that is docking to this
  763.    * @param dp the DockPosition where it wants to dock to
  764.    */
  765.   void docking( KDockWidget* dw, KDockWidget::DockPosition dp);
  766.  
  767.   /**
  768.    * Signals that the dock default position is set.
  769.    */
  770.   void setDockDefaultPos();
  771.  
  772.   /**
  773.    * Emitted when the close button of the panel ( KDockWidgetHeader) has been clicked.
  774.    */
  775.   void headerCloseButtonClicked();
  776.  
  777.   /**
  778.    * Emitted when the dockback button of the panel ( KDockWidgetHeader) has been clicked.
  779.    */
  780.   void headerDockbackButtonClicked();
  781.  
  782.   /**
  783.    * Emitted when the widget processes a close event.
  784.    */
  785.   void iMBeingClosed();
  786.   /**
  787.    * Emitted when the widget has undocked.
  788.    */
  789.   void hasUndocked();
  790.  
  791. protected slots:
  792.  
  793.   /** Does several things here when it has noticed that the former brother widget (closest neighbor) gets lost.
  794.    * The former brother widget is needed for a possible dockback action, to speak with the Beatles:
  795.    * "To get back to where you once belonged" ;-)
  796.    */
  797.   void loseFormerBrotherDockWidget();
  798.  
  799.   virtual void paintEvent(QPaintEvent*);
  800.  
  801.   virtual void mousePressEvent(QMouseEvent*);
  802.   virtual void mouseReleaseEvent(QMouseEvent*);
  803.   virtual void mouseMoveEvent(QMouseEvent*);
  804.   virtual void leaveEvent(QEvent*);
  805. protected:
  806.   friend class KDockWidgetHeader;
  807.   /**
  808.    * earlier closest neighbor widget, so it's possible to dock back to it.
  809.    */
  810.   KDockWidget* formerBrotherDockWidget;
  811.   /**
  812.    * the current dock position.
  813.    */
  814.   DockPosition currentDockPos;
  815.   /**
  816.    * the former dock position when it really was at another position before.
  817.    */
  818.   DockPosition formerDockPos;
  819.   /**
  820.    * a string used as tooltip for the tab page header when in dock-centered mode.
  821.    */
  822.   QString toolTipStr;
  823.   /**
  824.    * a string used as title of the tab page when in tab page mode
  825.    */
  826.   QString tabPageTitle;
  827.  
  828. private:
  829.   /**
  830.    * Sets the caption (window title) of the given tab widget.
  831.    *
  832.    * @param g the group (tab) widget
  833.    */
  834.   void setDockTabName( KDockTabGroup* g);
  835.  
  836.   /**
  837.    * Reparent to s or set this to the KDockMainWindow's view if s is that dockmainwindow.
  838.    * If s is O, simply move the widget.
  839.    *
  840.    * @param s the target widget to reparent to
  841.    * @param p the point to move to (if it doesn't reparent)
  842.    */
  843.   void applyToWidget( QWidget* s, const QPoint& p  = QPoint(0,0) );
  844.  
  845.   /**
  846.    * A base class pointer to the header of this dockwidget
  847.    */
  848.   KDockWidgetAbstractHeader* header;
  849.  
  850.   /**
  851.    * the embedded widget
  852.    */
  853.   QWidget* widget;
  854.  
  855.   /**
  856.    * the layout manager that takes care about proper resizing and moving the embedded widget and the header
  857.    */
  858.   QVBoxLayout* layout;
  859.  
  860.   /**
  861.    * the responsible dockmanager
  862.    */
  863.   KDockManager* manager;
  864.  
  865.   /**
  866.    * an icon for the tab widget header
  867.    */
  868.   QPixmap* pix;
  869.  
  870.   /**
  871.    * Information about the ability for docking to another dockwidget.
  872.    */
  873.   int eDocking;
  874.  
  875.   /**
  876.    * Information which site of this dockwidget is free for docking of other dockwidgets.
  877.    */
  878.   int sDocking;
  879.  
  880.   /**
  881.    * Previous side (left,right,top,bottom) where this dockwidget was before a dragging action, none if it wasn't dragged before.
  882.    */
  883.   KDockWidget::DockPosition prevSideDockPosBeforeDrag;
  884.  
  885.   // GROUP data
  886.   QString firstName;
  887.   QString lastName;
  888.   Orientation splitterOrientation;
  889.   bool isGroup;
  890.   bool isTabGroup;
  891. protected:
  892.   virtual void virtual_hook( int id, void* data );
  893. private:
  894.   KDockWidgetPrivate *d;
  895. };
  896.  
  897. /**
  898.  * The manager that knows all dockwidgets and handles the dock process (and member of the dockwidget class set).
  899.  * More or less a helper class for the KDockWidget class set but of interest for some functionality
  900.  * that can be called within a KDockMainWindow or a KDockWidget .
  901.  *
  902.  * An important feature is the ability to read or save the current state of all things concerning to
  903.  * dockwidgets to KConfig .
  904.  *
  905.  * The dockmanager is also often used when a certain dockwidget or a child of such dockwidget must be found.
  906.  *
  907.  * @author Max Judin (documentation: Falk Brettschneider).
  908.  */
  909. class KDEUI_EXPORT KDockManager: public QObject
  910. {
  911.   Q_OBJECT
  912. friend class KDockWidget;
  913. friend class KDockMainWindow;
  914.  
  915. public:
  916.     enum EnReadDockConfigMode {
  917.         Unknown,
  918.         WrapExistingWidgetsOnly,
  919.         RestoreAllDockwidgets
  920.     };
  921.  
  922. public:
  923.   /**
  924.    * Constructs a dockmanager. Some initialization happen:
  925.    * @li It installs an event filter for the main window,
  926.    * @li a control list for dock objects
  927.    * @li a control list for menu items concerning to menus provided by the dockmanager
  928.    * @li Some state variables are set
  929.    *
  930.    * @param mainWindow the main window controlled by this
  931.    * @param name the internal QOject name
  932.    */
  933.   KDockManager( QWidget* mainWindow, const char* name = 0L );
  934.  
  935.   /**
  936.    * Destructs a dockmanager.
  937.    */
  938.   virtual ~KDockManager();
  939.  
  940.   void dumpDockWidgets();
  941.  
  942. #ifndef NO_KDE2
  943.   /**
  944.    * Saves the current state of the dockmanager and of all controlled widgets.
  945.    * State means here to save the geometry, visibility, parents, internal object names, orientation,
  946.    * separator positions, dockwidget-group information, tab widget states (if it is a tab group) and
  947.    * last but not least some necessary things for recovering the dockmainwindow state.
  948.    *
  949.    * @param c the KDE configuration saver
  950.    * @param group the name of the section in KConfig
  951.    */
  952.   void writeConfig( KConfig* c = 0L, QString group = QString::null );
  953.  
  954.   /**
  955.    * Like writeConfig but reads the whole stuff in.
  956.    *
  957.    * In order to restore a window configuration
  958.    * from a config file, it looks up widgets by name
  959.    * (QObject::name) in the childDock variable of
  960.    * KDockManager. This list in turn contains all
  961.    * KDockWidgets (according to the KDockWidget constructor).
  962.    * So in principle, in order to restore a window layout,
  963.    * one must first construct all widgets, put each of them in a
  964.    * KDockWidget and then call readConfig(). And for all that
  965.    * to work, each widget must have a unique name.
  966.    *
  967.    * @param c the KDE configuration saver
  968.    * @param group the name of the section in KConfig
  969.    */
  970.   void readConfig ( KConfig* c = 0L, QString group = QString::null );
  971. #endif
  972.  
  973.   /// @since 3.1
  974.   void setMainDockWidget2(KDockWidget *);
  975.  
  976.   /**
  977.    * Saves the current dock window layout into a DOM tree below the given element.
  978.    */
  979.   void writeConfig(QDomElement &base);
  980.   /**
  981.    * Reads the current dock window layout from a DOM tree below the given element.
  982.    */
  983.   void readConfig(QDomElement &base);
  984.  
  985.   /**
  986.    * Shows all encapsulated widgets of all controlled dockwidgets and shows all dockwidgets which are
  987.    * parent of a dockwidget tab group.
  988.    */
  989.   void activate();
  990.  
  991.   /**
  992.    * It's more or less a method that catches several events which are interesting for the dockmanager.
  993.    * Mainly mouse events during the drag process of a dockwidgets are of interest here.
  994.    *
  995.    * @param object the object that sends the event
  996.    * @param event the event
  997.    * @return the return value of the method call of the base class method
  998.    */
  999.   virtual bool eventFilter( QObject * object, QEvent * event );
  1000.  
  1001.   /**
  1002.    * This method finds out what a widgets' dockwidget is. That means the dockmanager has a look at all
  1003.    * dockwidgets it knows and tells you when one of those dockwidgets covers the given widget.
  1004.    *
  1005.    * @param w any widget that is supposed to be encapsulated by one of the controlled dockwidgets
  1006.    * @return the dockwidget that encapsulates that widget, otherwise 0
  1007.    */
  1008.   KDockWidget* findWidgetParentDock( QWidget* w) const;
  1009.  
  1010.   /**
  1011.    * Works like makeDockVisible() but can be called for widgets that covered by a dockwidget.
  1012.    *
  1013.    * @param w the widget that is encapsulated by a dockwidget that turns to visible.
  1014.    */
  1015.   void makeWidgetDockVisible( QWidget* w ){ findWidgetParentDock(w)->makeDockVisible(); }
  1016.  
  1017.   /**
  1018.    * @return the popupmenu for showing/hiding dockwidgets
  1019.    */
  1020.   QPopupMenu* dockHideShowMenu() const { return menu; }
  1021.  
  1022.   /**
  1023.    * @param dockName an internal QObject name
  1024.    * @return the dockwidget that has got that internal QObject name
  1025.    */
  1026.   KDockWidget* getDockWidgetFromName( const QString& dockName );
  1027.  
  1028.   /**
  1029.    * Enables opaque resizing. Opaque resizing defaults to KGlobalSettings::opaqueResize().
  1030.    * Call this method before you create any dock widgets!
  1031.    */
  1032.   void setSplitterOpaqueResize(bool b=true);
  1033.  
  1034.   /**
  1035.    * Returns true if opaque resizing is enabled, false otherwise.
  1036.    */
  1037.   bool splitterOpaqueResize() const;
  1038.  
  1039.   /**
  1040.    * Try to preserve the widget's size. Works like KeepSize resize mode
  1041.    * of QSplitter. Off by default.
  1042.    * Call this method before you create any dock widgets!
  1043.    */
  1044.   void setSplitterKeepSize(bool b=true);
  1045.  
  1046.   /**
  1047.    * Returns true if the KeepSize is enabled, false otherwise.
  1048.    */
  1049.   bool splitterKeepSize() const;
  1050.  
  1051.   /**
  1052.    * Operate the splitter with a higher resolution. Off by default.
  1053.    * Call this method before you create any dock widgets!
  1054.    * If high resolution is used all splitter position parameters
  1055.    * are percent*100 instead of percent.
  1056.    * @note Since KDE 3.5 this is ignored. Internally the splitter always
  1057.    *       calcualtes in high resolution values. For KDE 4, this will be removed.
  1058.    */
  1059.   void setSplitterHighResolution(bool b=true);
  1060.  
  1061.   /**
  1062.    * Returns true if the splitter uses the high resolution, false otherwise.
  1063.    */
  1064.   bool splitterHighResolution() const;
  1065.  
  1066.   /**
  1067.    * @since 3.2
  1068.    */
  1069.   void setSpecialLeftDockContainer(KDockWidget* container);
  1070.   void setSpecialTopDockContainer(KDockWidget* container);
  1071.   void setSpecialRightDockContainer(KDockWidget* container);
  1072.   void setSpecialBottomDockContainer(KDockWidget* container);
  1073.  
  1074.   void removeFromAutoCreateList(KDockWidget* pDockWidget);
  1075.   void finishReadDockConfig();
  1076.   void setReadDockConfigMode(int mode);
  1077.  
  1078. signals:
  1079.  
  1080.   /**
  1081.    * Signals changes of the docking state of a dockwidget. Usually the dock-toolbar will be updated then.
  1082.    */
  1083.   void change();
  1084.  
  1085.   /**
  1086.    * Signals a dockwidget is replaced with another one.
  1087.    */
  1088.   void replaceDock( KDockWidget* oldDock, KDockWidget* newDock );
  1089.  
  1090.   /**
  1091.    * Signals a dockwidget without parent (toplevel) is shown.
  1092.    */
  1093.   void setDockDefaultPos( KDockWidget* );
  1094.  
  1095. private slots:
  1096.  
  1097.   /**
  1098.    * Clears the popupmenu for showing/hiding dockwidgets and fills it with the current states of all controlled dockwidgets.
  1099.    */
  1100.   void slotMenuPopup();
  1101.  
  1102.   /**
  1103.    * This method assumes a menuitem of the popupmenu for showing/hiding dockwidgets is selected and toggles that state.
  1104.    *
  1105.    * @param id the popupmenu id of the selected menuitem
  1106.    */
  1107.   void slotMenuActivated( int id);
  1108.  
  1109.   /* clears the old drawn drag rectangle (oldDragRect) from screen and
  1110.    * draws the new current drag rectangle (dragRect) depending on the current mouse position.
  1111.    * This highlights the dockwidget which is the currently chosen target during a dock action.
  1112.    */
  1113.   void drawDragRectangle();
  1114.  
  1115. private:
  1116.  
  1117.   /**
  1118.    * A data structure containing data about every dockwidget that is under control.
  1119.    */
  1120.   struct MenuDockData
  1121.   {
  1122.     MenuDockData( KDockWidget* _dock, bool _hide )
  1123.     {
  1124.       dock = _dock;
  1125.       hide = _hide;
  1126.     }
  1127.     ~MenuDockData(){}
  1128.  
  1129.     KDockWidget* dock;
  1130.     bool hide;
  1131.   };
  1132.  
  1133.   /**
  1134.    * Finds the KDockWidget at the position given as parameter
  1135.    *
  1136.    * @param pos global (desktop) position of the wanted dockwidget
  1137.    * @return the dockwidget at that position
  1138.    */
  1139.   KDockWidget* findDockWidgetAt( const QPoint& pos );
  1140.  
  1141.   /**
  1142.    * Finds the QWidget recursively at the position given as parameter
  1143.    *
  1144.    * @param w a variable where the method puts the QWidget at that position (instead of a return value)
  1145.    * @param p the parent widget where the recursive search should start from
  1146.    * @param pos global (desktop) position of the wanted dockwidget
  1147.    */
  1148.   void findChildDockWidget( QWidget*& w, const QWidget* p, const QPoint& pos );
  1149.  
  1150.   /**
  1151.    * Finds all dockwidgets which are child, grandchild and so on of p.
  1152.    *
  1153.    * @param p the parent widget where the recursive search starts from
  1154.    * @param l the widget list that contains the search result after the return of this method
  1155.    */
  1156.   void findChildDockWidget( const QWidget* p, QWidgetList*& l);
  1157.  
  1158.   /**
  1159.    * Sets a dockwidget in drag mode.
  1160.    */
  1161.   void startDrag( KDockWidget* );
  1162.  
  1163.   /**
  1164.    * Moves a dockwidget that is in drag mode.
  1165.    *
  1166.    * @param d the dockwidget which is dragged
  1167.    * @param pos the new position of the dragged dockwidget
  1168.    */
  1169.   void dragMove( KDockWidget* d, QPoint pos );
  1170.  
  1171.   /**
  1172.    * Aborts the drag mode. Restores the cursor and hides the drag indicator.
  1173.    */
  1174.   void cancelDrop();
  1175.  
  1176.   /**
  1177.    * Finishes the drag mode. If the user let it drop on an other dockwidget, it will possibly be docked (if allowed),
  1178.    * if the user drops it outside of the application window it becomes toplevel.
  1179.    */
  1180.   void drop();
  1181.  
  1182. // class members
  1183.  
  1184.   /**
  1185.    * Usually the KDockMainWindow but not necessarily.
  1186.    */
  1187.   QWidget* main;
  1188.  
  1189.   /**
  1190.    * The dockwidget that is being dragged at the moment
  1191.    */
  1192.   KDockWidget* currentDragWidget;
  1193.  
  1194.   /**
  1195.    * The target dockwidget where the currentDragWidget is dropped
  1196.    */
  1197.   KDockWidget* currentMoveWidget; // widget where mouse moving
  1198.  
  1199.   /**
  1200.    * It is of interest during the dock process. Then it contains all child dockwidgets.
  1201.    */
  1202.   QWidgetList* childDockWidgetList;
  1203.  
  1204.   /**
  1205.    * The dockposition where the dockwidget would be docked to, if we dropped it here.
  1206.    */
  1207.   KDockWidget::DockPosition curPos;
  1208.  
  1209.   /**
  1210.    * A QList of all objects that are important for docking.
  1211.    * Some serve as group widgets of dockwidgets, others encapsulate normal widgets.
  1212.    */
  1213.   QObjectList* childDock;
  1214.  
  1215.   /**
  1216.    * Contains dockwidgets that are created automatically by the dockmanager. For internal use.
  1217.    */
  1218.   QObjectList* autoCreateDock;
  1219.  
  1220.   /**
  1221.    * For storing the width during the dragging of a dockwidget.
  1222.    */
  1223.   int storeW;
  1224.  
  1225.   /**
  1226.    *  For storing the height during the dragging of a dockwidget.
  1227.    */
  1228.   int storeH;
  1229.  
  1230.   /**
  1231.    * State variable if there is a drag process active.
  1232.    */
  1233.   bool dragging;
  1234.  
  1235.   /**
  1236.    * State variable if there is an undock process active
  1237.    */
  1238.   bool undockProcess;
  1239.  
  1240.   /**
  1241.    * The dockmanager sets it to true if the user cancels the drag by moving the cursor
  1242.    * on a invalid drop place
  1243.    */
  1244.   bool dropCancel;
  1245.  
  1246.   /**
  1247.    * A popup menu that contains one menuitem for each dockwidget that shows the current visibility state and
  1248.    * to show or hide the appropriate dockwidget.
  1249.    */
  1250.   QPopupMenu* menu;
  1251.  
  1252.   /**
  1253.    * An internal list containing data for the menuitems for the visibility popup menu.
  1254.    */
  1255.   QPtrList<MenuDockData> *menuData;
  1256.  
  1257. protected:
  1258.   virtual void virtual_hook( int id, void* data );
  1259. private:
  1260.   class KDockManagerPrivate;
  1261.   KDockManagerPrivate *d;
  1262. };
  1263.  
  1264. /**
  1265.  * A special kind of KMainWindow that is able to have dockwidget child widgets (and member of the dockwidget class set).
  1266.  *
  1267.  * The main widget should be a KDockWidget where other KDockWidget can be docked to
  1268.  * the left, right, top, bottom or to the middle.
  1269.  * Note: dock to the middle means to drop on a dockwidget and to unite them to a new widget, a tab control.
  1270.  *
  1271.  * Furthermore, the KDockMainWindow has got the KDockManager and some data about the dock states.
  1272.  *
  1273.  * If you've got some dockwidgets, you can dock them to the dockmainwindow to initialize a start scene:
  1274.  * Here an example:
  1275.  * \code
  1276.  * DockApplication::DockApplication( const char* name) : KDockMainWindow( name)
  1277.  * {
  1278.  *   ...
  1279.  *   KDockWidget* mainDock;
  1280.  *   mainDock = createDockWidget( "Falk's MainDockWidget", mainPixmap, 0L, "main_dock_widget");
  1281.  *   AnyContentsWidget* cw = new AnyContentsWidget( mainDock);
  1282.  *   mainDock->setWidget( cw);
  1283.  *   // allow others to dock to the 4 sides
  1284.  *   mainDock->setDockSite(KDockWidget::DockCorner);
  1285.  *   // forbit docking abilities of mainDock itself
  1286.  *   mainDock->setEnableDocking(KDockWidget::DockNone);
  1287.  *   setView( mainDock); // central widget in a KDE mainwindow
  1288.  *   setMainDockWidget( mainDock); // master dockwidget
  1289.  *   ...
  1290.  *   KDockWidget* dockLeft;
  1291.  *   dockLeft = createDockWidget( "Intially left one", anyOtherPixmap, 0L, i18n("The left dockwidget"));
  1292.  *   AnotherWidget* aw = new AnotherWidget( dockLeft);
  1293.  *   dockLeft->setWidget( aw);
  1294.  *   dockLeft->manualDock( mainDock,              // dock target
  1295.  *                         KDockWidget::DockLeft, // dock site
  1296.  *                         20 );                  // relation target/this (in percent)
  1297.  *   ...
  1298.  * \endcode
  1299.  *
  1300.  * Docking is fully dynamic at runtime. That means you can always move dockwidgets via drag and drop.
  1301.  *
  1302.  * And last but not least you can use the popupmenu for showing or hiding any controlled dockwidget
  1303.  * of this class and insert it to your main menu bar or anywhere else.
  1304.  *
  1305.  * @author Max Judin (documentation: Falk Brettschneider).
  1306.  */
  1307. class KDEUI_EXPORT KDockMainWindow : public KMainWindow
  1308. {
  1309.   Q_OBJECT
  1310.  
  1311. friend class KDockManager;
  1312.  
  1313. public:
  1314.  
  1315.   /**
  1316.    * Constructs a dockmainwindow. It calls its base class constructor and does additional things concerning
  1317.    * to the dock stuff:
  1318.    * @li information about the dock state of this' children gets initialized
  1319.    * @li a dockmanager is created...
  1320.    * @li ...and gets initialized
  1321.    * @li the main dockwidget is set to 0
  1322.    *
  1323.    * @param parent Parent widget for the dock main widget
  1324.    * @param name internal object name
  1325.    * @param f Qt::WidgetFlags widget flags
  1326.    */
  1327.   KDockMainWindow( QWidget* parent = 0L, const char *name = 0L, WFlags f = WType_TopLevel | WDestructiveClose );
  1328.  
  1329.   /**
  1330.    * Destructs a dockmainwindow.
  1331.    */
  1332.   virtual ~KDockMainWindow();
  1333.  
  1334.   /**
  1335.    * Returns the dockmanager of this. (see KDockManager)
  1336.    * @return pointer to the wanted dockmanager
  1337.    */
  1338.   KDockManager* manager() const { return dockManager; }
  1339.  
  1340.   /**
  1341.    * Sets a new main dockwidget.
  1342.    * Additionally, the toolbar is re-initialized.
  1343.    *
  1344.    * @param dockwidget dockwidget that become the new main dockwidget
  1345.    */
  1346.   void setMainDockWidget( KDockWidget* dockwidget);
  1347.  
  1348.   /**
  1349.    * Returns the main dockwidget.
  1350.    *
  1351.    * @return pointer to the main dockwidget
  1352.    */
  1353.   KDockWidget* getMainDockWidget() const { return mainDockWidget; }
  1354.  
  1355.   /**
  1356.    * This is one of the most important methods!
  1357.    * The KDockMainWindow creates a new dockwidget object here that usually should encapsulate the user's widget.
  1358.    * The new dockwidget is automatically taken under control by the dockmanager of the dockmainwindow.
  1359.    *
  1360.    * @param name   QObject name (default dockwidget caption)
  1361.    * @param pixmap window icon (for instance shown when docked as tabwidget entry)
  1362.    * @param parent parent widget for the new dockwidget
  1363.    * @param strCaption  window title (shown when toplevel)
  1364.    * @param strTabPageLabel title of the tab page (visible when in tab page mode), if it is "", only the icon will be shown; if it is 0L, the label is set to strCaption
  1365.    * @return    a pointer to the new created dockwidget
  1366.    */
  1367.   KDockWidget* createDockWidget( const QString& name, const QPixmap &pixmap, QWidget* parent = 0L,
  1368.     const QString& strCaption = QString::null, const QString& strTabPageLabel = QString::fromLatin1( " " ) );
  1369.  
  1370.   /**
  1371.    * Saves the current dock window layout into a DOM tree below the given element.
  1372.    */
  1373.   void writeDockConfig(QDomElement &base);
  1374.   /**
  1375.    * Reads the current dock window layout from a DOM tree below the given element.
  1376.    */
  1377.   void readDockConfig(QDomElement &base);
  1378.  
  1379. #ifndef NO_KDE2
  1380.   /**
  1381.    * It writes the current dock state in the given section of KConfig.
  1382.    *
  1383.    * @param c     KDE class for saving configurations
  1384.    * @param group name of section to write to
  1385.    */
  1386.   void writeDockConfig( KConfig* c = 0L, QString group = QString::null );
  1387.  
  1388.   /**
  1389.    * It reads the current dock state from the given section of KConfig.
  1390.    *
  1391.    * @param c     KDE class for saving configurations
  1392.    * @param group name of section to read from
  1393.    */
  1394.   void readDockConfig ( KConfig* c = 0L, QString group = QString::null );
  1395. #endif
  1396.  
  1397.   /**
  1398.    * It runs through all dockwidgets which are under control of the dockmanager and calls show() for every
  1399.    * encapsulated widget and show() for the dockwidget itself if it is not in tab mode.
  1400.    * Additionally, if the main dockwidget is not a QDialog, it will be shown.
  1401.    */
  1402.   void activateDock(){ dockManager->activate(); }
  1403.  
  1404.   /**
  1405.    * Returns a popup menu that contains entries for all controlled dockwidgets making hiding and showing
  1406.    * them possible.
  1407.    *
  1408.    * @return the wanted popup menu
  1409.    */
  1410.   QPopupMenu* dockHideShowMenu() const { return dockManager->dockHideShowMenu(); }
  1411.  
  1412.   /**
  1413.    * This method shows the given dockwidget.
  1414.    * The clue is that it also considers the dockwidget could be a tab page
  1415.    * and must set to be the activate one.
  1416.    *
  1417.    * @param dock the dockwidget that is to be shown
  1418.    */
  1419.   void makeDockVisible( KDockWidget* dock );
  1420.  
  1421.   /**
  1422.    * This method hides the given dockwidget.
  1423.    *
  1424.    * @param dock the dockwidget that is to be shown
  1425.    */
  1426.   void makeDockInvisible( KDockWidget* dock );
  1427.  
  1428.   /**
  1429.    * This is an overloaded member function, provided for convenience.
  1430.    * It differs from the above function only in what argument(s) it accepts.
  1431.    */
  1432.   void makeWidgetDockVisible( QWidget* widget );
  1433.  
  1434.   /**
  1435.    * This method calls the base class method.
  1436.    * If the given widget inherits KDockWidget, applyToWidget(this) is called.
  1437.    *
  1438.    * @param widget any widget that should become the main view
  1439.    */
  1440.   void setView( QWidget * widget );
  1441.  
  1442. signals:
  1443.   /**
  1444.   * Signals a certain dockwidget is undocked now.
  1445.   */
  1446.   void dockWidgetHasUndocked(KDockWidget*);
  1447.  
  1448. protected:
  1449.  
  1450.   /**
  1451.    * A pointer to the main dockwidget (where one can manualDock() to
  1452.    */
  1453.   KDockWidget* mainDockWidget;
  1454.  
  1455.   /**
  1456.    * A pointer to the manager for the dock process
  1457.    */
  1458.   KDockManager* dockManager;
  1459.  
  1460. protected slots:
  1461.   /**
  1462.   * Called whenever one of the dockwidgets of this has been undocked.
  1463.   */
  1464.   void slotDockWidgetUndocked();
  1465.  
  1466. protected:
  1467.   virtual void virtual_hook( int id, void* data );
  1468. private:
  1469.   class KDockMainWindowPrivate;
  1470.   KDockMainWindowPrivate *d;
  1471. };
  1472.  
  1473. class KDEUI_EXPORT KDockArea : public QWidget
  1474. {
  1475.   Q_OBJECT
  1476.  
  1477. friend class KDockManager;
  1478.  
  1479. public:
  1480.  
  1481.  
  1482.   KDockArea( QWidget* parent = 0L, const char *name = 0L);
  1483.  
  1484.   virtual ~KDockArea();
  1485.  
  1486.   KDockManager* manager(){ return dockManager; }
  1487.  
  1488.  
  1489.   void setMainDockWidget( KDockWidget* );
  1490.   KDockWidget* getMainDockWidget(){ return mainDockWidget; }
  1491.  
  1492.   KDockWidget* createDockWidget( const QString& name, const QPixmap &pixmap, QWidget* parent = 0L,
  1493.     const QString& strCaption = QString::null, const QString& strTabPageLabel = QString::fromLatin1( " " ) );
  1494.  
  1495.   void writeDockConfig(QDomElement &base);
  1496.   void readDockConfig(QDomElement &base);
  1497.  
  1498. #ifndef NO_KDE2
  1499.   void writeDockConfig( KConfig* c = 0L, QString group = QString::null );
  1500.   void readDockConfig ( KConfig* c = 0L, QString group = QString::null );
  1501. #endif
  1502.  
  1503.  
  1504.  
  1505.   void activateDock(){ dockManager->activate(); }
  1506.   QPopupMenu* dockHideShowMenu(){ return dockManager->dockHideShowMenu(); }
  1507.   void makeDockVisible( KDockWidget* dock );
  1508.   void makeDockInvisible( KDockWidget* dock );
  1509.   void makeWidgetDockVisible( QWidget* widget );
  1510.   //void setView( QWidget* );
  1511.  
  1512. signals:
  1513.   /**
  1514.   * Signals a certain dockwidget is undocked now.
  1515.   */
  1516.   void dockWidgetHasUndocked(KDockWidget*);
  1517.  
  1518. protected:
  1519.  
  1520.   KDockWidget* mainDockWidget;
  1521.   KDockManager* dockManager;
  1522.  
  1523. protected slots:
  1524.   void slotDockWidgetUndocked();
  1525.  
  1526. public:
  1527.     virtual void resizeEvent(QResizeEvent *);
  1528.  
  1529. protected:
  1530.   virtual void virtual_hook( int id, void* data );
  1531. private:
  1532.   class KDockMainWindowPrivate;
  1533.   KDockMainWindowPrivate *d;
  1534. };
  1535.  
  1536.  
  1537. #endif
  1538.  
  1539.  
  1540.